<template>
  <div class="container">
    
    <div class="container-people bg-light" style="position: relative">
      <el-card shadow="hover" class="my-card"
      >
        <i class="el-icon-menu"></i>
        <h6 class="my-pointer" @click="pagination.label='';getAll()">文章分类</h6>
        <ul>
          <!--右边列表区域 暂时写死-->
          <li @click="pagination.label = label.label;getAll()" v-for="(label,index) in labelList" :key="index">
            <el-tag class="mb-1 mt-1" :type="type[index]">{{label.label}}</el-tag>
            <span class="badge text-bg-secondary count mt-2">{{ label.count }}</span>
          </li>

        </ul>
      </el-card>
      
      <!--博客基本信息列表-->
      <div class="alert alert-dark mt-3 alter_list" role="alert"
           v-for="(blog, index) in blog_list"
           :key="index">
        <a @click="goto(blog.blogId)" target="_blank" style="cursor:pointer">
          <h5>{{ blog.title }}</h5>
          <div>
            👨‍💻 作者 {{ blog.username }}
            📅 {{ blog.releaseTime }}
            📂 {{ blog.label }}
          </div>
        </a>
      </div>
      
      
      <!--分页模型-->
      <div class="block" style="margin-left: 300px;">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pagination.page"
          :page-sizes="[6, 8, 10, 15]"
          :page-size="pagination.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="pageTotal">
        </el-pagination>
      </div>
    </div>
    
  </div>
</template>

<script>
import {getAllBlog, getBlogLabelCount} from '@/api/blog/blogApi'

export default {
  name: "UserArticle",
  data() {
    return {
      // 模拟数据 => 实际上接收到数据直接覆盖假的数据
      blog_list: [],
      labelList: [],
      pageTotal: 0, //总记录数
      pagination: {//分页相关模型数据
        page: 1, //当前页码
        label:'', // 标签
        pageSize: 6, // 每页要展示多少条数据 默认为6条
      },
      type:[
        "",
        "success",
        "info",
        "warning",
        "danger",
        "",
        "success",
        "info",
        "warning",
        "danger",
      ]
    }
  },
  created() {
    this.getAll()
    this.getLabelCount()
  },
  methods: {
    handleCurrentChange(val) {
      this.pagination.page = val
      this.getAll()
    },
    
    handleSizeChange(val) {
      this.pagination.pageSize = val
      this.getAll()
    },
    goto(blogId) {
      let routeData = this.$router.resolve({
        path: "/showcase-the-article",
        query: {
          blogId
        }
      });
      window.open(routeData.href, '_blank');
    },
    
    getAll() {
      this.isPagination = true
      getAllBlog(this.pagination).then(res => {
        this.blog_list = res.data.data
        this.pageTotal = parseInt(res.data.message)
      })
    },
    getLabelCount() {
      getBlogLabelCount().then((res) => {
        this.labelList = res.data.data
      })
    },
  }
}
</script>

<style scoped>
a {
  text-decoration: none;
  color: black;
}

.container-people {
  color: #969696;
  padding: 10px;
  width: 1250px;
  border-radius: 20px;
}

ul {
  padding: 0;
  margin: 0;
}

li {
  cursor: pointer;
  margin-bottom: 20px;
  padding: 0 10px;
  border-radius: 8px;
  list-style: none;
  transition: all 0.35s;
}

li:hover {
  background-color: rgb(241, 242, 243);
  transform: scale(1.1);
}

.count {
  float: right;
  margin-top: 6px;
}

.my-card {
  width: 250px;
  height: 540px;
  border-radius: 20px;
  margin-right: 20px;
  position: absolute;
  top: 25px;
  right: 0;
}

.alter_list {
  width: 900px;
  margin-left: 30px;
  transition: all 0.35s;
}

.alter_list:hover {
  transform: scale(1.03);
}

.my-pointer {
  display: inline;
  margin-left: 10px;
  cursor: pointer;
}


</style>